//=============================================================================
/**
 *
 *	@file		encount_effect_gym.c
 *	@brief		エンカウントエフェクト(ジム、四天王、チャンピオン)
 *	@author		hosaka genya
 *	@data		2009.02.23	オンメモリが足りないので encount_effect_sub から切り出し
 *
 */
//=============================================================================
#include "common.h"
#include "system/brightness.h"
#include "fieldsys.h"
#include "fieldmap_work.h"
#include "field_event.h"
#include "fld_motion_bl.h"
#include "encount_effect_def.h"
#include "system/wipe.h"
#include "system/laster.h"
#include "system/fontproc.h"
#include "field_encounteffect.naix"
#include "savedata/mystatus.h"
#include "include/battle/trtype_def.h"
#include "include/battle/trno_def.h"
#include "include/msgdata/msg.naix"

#define PLATINUM_MERGE_MSG

#ifdef PLATINUM_MERGE_MSG
#include "include/msgdata/msg_encount_effect.h"
#endif

#include "field/fieldmap.h"

#include "encount_effect_gym.h"

//-----------------------------------------------------------------------------
/**
 *					コーディング規約
 *		●関数名
 *				１文字目は大文字それ以降は小文字にする
 *		●変数名
 *				・変数共通
 *						constには c_ を付ける
 *						staticには s_ を付ける
 *						ポインタには p_ を付ける
 *						全て合わさると csp_ となる
 *				・グローバル変数
 *						１文字目は大文字
 *				・関数内変数
 *						小文字と”＿”と数字を使用する 関数の引数もこれと同じ
*/
//-----------------------------------------------------------------------------

//-----------------------------------------------------------------------------
/**
 *
 *			特殊トレーナー　エンカウント[ SP_TR ]
 *
 */
//-----------------------------------------------------------------------------
static void EncountEffect_SPTR_ResColorChange( CLACT_WORK_PTR clact, HEAPID heap, int nclr, u8 evy, u16 next_rgb );

//=============================================================================
/**
 *								定数定義
 */
//=============================================================================

//-------------------------------------
//	ジムリーダー
//=====================================
// シーケンス
enum{
	ENCOUNT_SPTR_GYM_START,
	ENCOUNT_SPTR_GYM_FLASH_INI,
	ENCOUNT_SPTR_GYM_FLASH_WAIT,
	ENCOUNT_SPTR_GYM_BG_IN,
	ENCOUNT_SPTR_GYM_BG_INWAIT,
	ENCOUNT_SPTR_GYM_VS_ANMWAIT,
	ENCOUNT_SPTR_GYM_OAM_IN,
	ENCOUNT_SPTR_GYM_OAM_INWAIT,
	ENCOUNT_SPTR_GYM_OAM_FLASH_OUT,
	ENCOUNT_SPTR_GYM_OAM_FLASH_OUT_WAIT,
	ENCOUNT_SPTR_GYM_OAM_FLASH_IN,
	ENCOUNT_SPTR_GYM_OAM_FLASH_IN_WAIT,
	ENCOUNT_SPTR_GYM_WAIT,
	ENCOUNT_SPTR_GYM_WIPE,
	ENCOUNT_SPTR_GYM_WIPEWAIT,
	ENCOUNT_SPTR_GYM_END,
};
// OAMデータ
// アクターデータ数
#define ENCOUNT_SPTR_GYM_CELL_NUM		( 8 )	// ワーク数
#define ENCOUNT_SPTR_GYM_CELL_RES_NUM	( 3 )	// リソース数
#define ENCOUNT_SPTR_GYM_CELL_CONT_ID	( 600000 )
#define ENCOUNT_SPTR_GYM_LEADER_SCALE_DEF	( FX32_CONST( 1.0f ) )	// リーダーの基本の拡大値
#define ENCOUNT_SPTR_GYM_LEADER_DRAW_BOTTOM	( 30 )	// 下はこのサイズまで表示する
#define ENCOUNT_SPTR_GYM_LEADER_COLOR_FADE		( GX_RGB( 0,0,0 ) )
#define ENCOUNT_SPTR_GYM_LEADER_COLOR_FADE_EVY	( 14 )
#define ENCOUNT_SPTR_GYM_LEADER_CHAR_OFS_CX	(0)	// キャラクタデータ書き出す時の、Xキャラクタオフセット値

#define ENCOUNT_SPTR_GYM_ZIGUZAGU_IN_WND ( GX_WND_PLANEMASK_BG0|GX_WND_PLANEMASK_BG1|GX_WND_PLANEMASK_BG2|GX_WND_PLANEMASK_BG3|GX_WND_PLANEMASK_OBJ)				// ジグザグ動さウィンドウ中
#define ENCOUNT_SPTR_GYM_ZIGUZAGU_OUT_WND ( GX_WND_PLANEMASK_BG0|GX_WND_PLANEMASK_BG1|GX_WND_PLANEMASK_BG2|GX_WND_PLANEMASK_OBJ)				// ジグザグ動さウィンドウ外
enum{	//VSOAM
	ENCOUNT_SPTR_GYM_VSOAM_ANM0,
	ENCOUNT_SPTR_GYM_VSOAM_ANM1,
	ENCOUNT_SPTR_GYM_VSOAM_ANM2,
	ENCOUNT_SPTR_GYM_VSOAM,
	ENCOUNT_SPTR_GYM_VSOAM_NUM,
};
#define ENCOUNT_SPTR_GYM_TRNAME_X		( 0 )	// トレーナー名Xキャラ座標
#define ENCOUNT_SPTR_GYM_TRNAME_Y		( 10 )	// トレーナー名Yキャラ座標
#define ENCOUNT_SPTR_GYM_TRNAME_SIZX	( 16 )	// トレーナー名BMPXキャラサイズ
#define ENCOUNT_SPTR_GYM_TRNAME_SIZY	( 2 )	// トレーナー名BMPYキャラサイズ
#define ENCOUNT_SPTR_GYM_TRNAME_CGX		( 1 )
#define ENCOUNT_SPTR_GYM_TRNAME_PAL		( 2 )
#define ENCOUNT_SPTR_GYM_TRNAME_COL		( GF_PRINTCOLOR_MAKE( 1, 2, 0 ) )

// 動さパラメータ	（触ってよい部分）
#define ENCOUNT_SPTR_GYM_OAM_START_X	( 272*FX32_ONE )	// OAM動さ開始X
#define ENCOUNT_SPTR_GYM_OAM_X_SS		( -64*FX32_ONE )	// 初期速度
#define ENCOUNT_SPTR_GYM_OAM_START_Y	( 66*FX32_ONE )		// OAMY座標
#define ENCOUNT_SPTR_GYM_OAM_MOVE_SYNC	( 4 )				// OAM動さシンク
#define ENCOUNT_SPTR_GYM_TRNAME_OFS_X	( -92 )				// OAMの位置から見てTRNAMEをどの位置に表示するか
#define ENCOUNT_SPTR_GYM_ZIGUZAGU_DOT	( 8 )				// ジグザグ区切りYドット数
#define ENCOUNT_SPTR_GYM_ZIGUZAGU_WIDTH	( 16 )				// ジグザグ幅
#define ENCOUNT_SPTR_GYM_ZIGUZAGU_SYNC	( 6 )				// ジグザグ動さシンク
#define ENCOUNT_SPTR_GYM_BG_CY			( 68 )	// BGの中心
#define ENCOUNT_SPTR_GYM_BG_AUTOMOVE_X	( 30 )	// AUTO動さスピード
#define ENCOUNT_SPTR_GYM_BG_AFTER_WAIT	( 10 )				// BG動さ後ウエイト
#define	ENCOUNT_SPTR_GYM_FLASHOUT_SYNC	( 3 )				// フラッシュアウトシンク数
#define	ENCOUNT_SPTR_GYM_FLASHIN_SYNC	( 3 )				// フラッシュインシンク数
#define ENCOUNT_SPTR_GYM_FLASH_AFTER_WAIT	( 26 )			// フラッシュ後のウエイト
#define ENCOUNT_SPTR_GYM_SCALE_S			( FX32_CONST(1.0f) )	// 拡大開始
#define ENCOUNT_SPTR_GYM_SCALE_E			( FX32_CONST(1.0f) )	// 拡大開始
#define ENCOUNT_SPTR_GYM_FADEOUT_SYNC		( 15 )			// フェードアウトシンク
#define ENCOUNT_SPTR_GYM_VSMARK_X		( FX32_CONST( 72 ) )	// VSMARKの位置
#define ENCOUNT_SPTR_GYM_VSMARK_Y		( FX32_CONST( 74 ) )	// VSMARKの位置
#define ENCOUNT_SPTR_GYM_VSANMSYNC		( 6 )	// １つの拡縮アニメのシンク数
#define ENCOUNT_SPTR_GYM_VSANMTIMING	( 3 )	//	次を出すタイミング
#define ENCOUNT_SPTR_GYM_3DAREA_BRIGHTNESS	( -14 )// 3D面を暗くする値

#define ENCOUNT_SPTR_CELL_CONT_ID	( 600000 )

// それぞれで変わるところ
typedef struct {
	fx32 end_x;
	u32	trno;
	u16 type;
	u16 tr_oam_chr_ofs_cx;
	u8	nclr;
	u8	ncgr;
	u8	ncer;
	u8	nanr;
	u8	bg_nclr;
	u8	bg_ncgr;
	u8	bg_nscr;
	u8	pad;
} ENCOUNT_SPTR_GYM_PARAM;

// それぞれの定数
static const ENCOUNT_SPTR_GYM_PARAM ENCOUNT_SPTR_GymDef[ 8+8 ] = {
	{	// 岩
		214*FX32_ONE,			// 動さ完了X座標
		LEADER1_01,
		TRTYPE_LEADER1,			// リーダータイプ
		ENC_OAM_TR_CHAR_CUT_CX,	// OAMキャラのオフセット
		NARC_field_encounteffect_trgs_face01_NCLR,
		NARC_field_encounteffect_trgs_face01_NCGR,
		NARC_field_encounteffect_trgs_face01_NCER,
		NARC_field_encounteffect_trgs_face01_NANR,
		NARC_field_encounteffect_cutin_gym01_NCLR,
		NARC_field_encounteffect_cutin_gym01_NCGR,
		NARC_field_encounteffect_cutin_gym01_NSCR,
		0,
	},
	{	// 草
		214*FX32_ONE,			// 動さ完了X座標
		LEADER2_01,
		TRTYPE_LEADER2,			// リーダータイプ
		ENC_OAM_TR_CHAR_CUT_CX,	// OAMキャラのオフセット
		NARC_field_encounteffect_trgs_face02_NCLR,
		NARC_field_encounteffect_trgs_face02_NCGR,
		NARC_field_encounteffect_trgs_face02_NCER,
		NARC_field_encounteffect_trgs_face02_NANR,
		NARC_field_encounteffect_cutin_gym02_NCLR,
		NARC_field_encounteffect_cutin_gym02_NCGR,
		NARC_field_encounteffect_cutin_gym02_NSCR,
		0,
	},
	{	// 水
		214*FX32_ONE,			// 動さ完了X座標
		LEADER3_01,
		TRTYPE_LEADER3,			// リーダータイプ
		ENCOUNT_SPTR_GYM_LEADER_CHAR_OFS_CX,// OAMキャラのオフセット値	基本的に水だけが、ENCOUNT_SPTR_GYM_LEADER_CHAR_OFS_CX
		NARC_field_encounteffect_trgs_face03_NCLR,
		NARC_field_encounteffect_trgs_face03_NCGR,
		NARC_field_encounteffect_trgs_face03_NCER,
		NARC_field_encounteffect_trgs_face03_NANR,
		NARC_field_encounteffect_cutin_gym03_NCLR,
		NARC_field_encounteffect_cutin_gym03_NCGR,
		NARC_field_encounteffect_cutin_gym03_NSCR,
		0,
	},
	{	// 格闘
		214*FX32_ONE,			// 動さ完了X座標
		LEADER4_01,
		TRTYPE_LEADER4,			// リーダータイプ
		ENC_OAM_TR_CHAR_CUT_CX,	// OAMキャラのオフセット
		NARC_field_encounteffect_trgs_face04_NCLR,
		NARC_field_encounteffect_trgs_face04_NCGR,
		NARC_field_encounteffect_trgs_face04_NCER,
		NARC_field_encounteffect_trgs_face04_NANR,
		NARC_field_encounteffect_cutin_gym04_NCLR,
		NARC_field_encounteffect_cutin_gym04_NCGR,
		NARC_field_encounteffect_cutin_gym04_NSCR,
		0,
	},
	{	// ゴースト
		214*FX32_ONE,			// 動さ完了X座標
		LEADER5_01,
		TRTYPE_LEADER5,			// リーダータイプ
		ENC_OAM_TR_CHAR_CUT_CX,	// OAMキャラのオフセット
		NARC_field_encounteffect_trgs_face05_NCLR,
		NARC_field_encounteffect_trgs_face05_NCGR,
		NARC_field_encounteffect_trgs_face05_NCER,
		NARC_field_encounteffect_trgs_face05_NANR,
		NARC_field_encounteffect_cutin_gym05_NCLR,
		NARC_field_encounteffect_cutin_gym05_NCGR,
		NARC_field_encounteffect_cutin_gym05_NSCR,
		0,
	},
	{	// 氷
		214*FX32_ONE,			// 動さ完了X座標
		LEADER6_01,
		TRTYPE_LEADER6,			// リーダータイプ
		ENC_OAM_TR_CHAR_CUT_CX,	// OAMキャラのオフセット
		NARC_field_encounteffect_trgs_face06_NCLR,
		NARC_field_encounteffect_trgs_face06_NCGR,
		NARC_field_encounteffect_trgs_face06_NCER,
		NARC_field_encounteffect_trgs_face06_NANR,
		NARC_field_encounteffect_cutin_gym06_NCLR,
		NARC_field_encounteffect_cutin_gym06_NCGR,
		NARC_field_encounteffect_cutin_gym06_NSCR,
		0,
	},
	{	// 鋼
		214*FX32_ONE,			// 動さ完了X座標
		LEADER7_01,
		TRTYPE_LEADER7,			// リーダータイプ
		ENC_OAM_TR_CHAR_CUT_CX,	// OAMキャラのオフセット
		NARC_field_encounteffect_trgs_face07_NCLR,
		NARC_field_encounteffect_trgs_face07_NCGR,
		NARC_field_encounteffect_trgs_face07_NCER,
		NARC_field_encounteffect_trgs_face07_NANR,
		NARC_field_encounteffect_cutin_gym07_NCLR,
		NARC_field_encounteffect_cutin_gym07_NCGR,
		NARC_field_encounteffect_cutin_gym07_NSCR,
		0,
	},
	{	// 電気
		214*FX32_ONE,			// 動さ完了X座標
		LEADER8_01,
		TRTYPE_LEADER8,			// リーダータイプ
		ENC_OAM_TR_CHAR_CUT_CX,	// OAMキャラのオフセット
		NARC_field_encounteffect_trgs_face08_NCLR,
		NARC_field_encounteffect_trgs_face08_NCGR,
		NARC_field_encounteffect_trgs_face08_NCER,
		NARC_field_encounteffect_trgs_face08_NANR,
		NARC_field_encounteffect_cutin_gym08_NCLR,
		NARC_field_encounteffect_cutin_gym08_NCGR,
		NARC_field_encounteffect_cutin_gym08_NSCR,
		0,
	},
	//--------------------------------------------------------
	// カントー
	//--------------------------------------------------------
	{
		214*FX32_ONE,			// 動さ完了X座標
		LEADER9_01,
		TRTYPE_LEADER9,			// リーダータイプ
		ENC_OAM_TR_CHAR_CUT_CX,	// OAMキャラのオフセット
		NARC_field_encounteffect_trgs_face09_NCLR,
		NARC_field_encounteffect_trgs_face09_NCGR,
		NARC_field_encounteffect_trgs_face09_NCER,
		NARC_field_encounteffect_trgs_face09_NANR,
		NARC_field_encounteffect_cutin_gym01_NCLR,
		NARC_field_encounteffect_cutin_gym01_NCGR,
		NARC_field_encounteffect_cutin_gym01_NSCR,
		0,
	},
	{
		214*FX32_ONE,			// 動さ完了X座標
		LEADER10_01,
		TRTYPE_LEADER10,			// リーダータイプ
		ENC_OAM_TR_CHAR_CUT_CX,	// OAMキャラのオフセット
		NARC_field_encounteffect_trgs_face10_NCLR,
		NARC_field_encounteffect_trgs_face10_NCGR,
		NARC_field_encounteffect_trgs_face10_NCER,
		NARC_field_encounteffect_trgs_face10_NANR,
		NARC_field_encounteffect_cutin_gym02_NCLR,
		NARC_field_encounteffect_cutin_gym02_NCGR,
		NARC_field_encounteffect_cutin_gym02_NSCR,
		0,
	},
	{
		214*FX32_ONE,			// 動さ完了X座標
		LEADER11_01,
		TRTYPE_LEADER11,			// リーダータイプ
		ENCOUNT_SPTR_GYM_LEADER_CHAR_OFS_CX,// OAMキャラのオフセット値	基本的に水だけが、ENCOUNT_SPTR_GYM_LEADER_CHAR_OFS_CX
		NARC_field_encounteffect_trgs_face11_NCLR,
		NARC_field_encounteffect_trgs_face11_NCGR,
		NARC_field_encounteffect_trgs_face11_NCER,
		NARC_field_encounteffect_trgs_face11_NANR,
		NARC_field_encounteffect_cutin_gym03_NCLR,
		NARC_field_encounteffect_cutin_gym03_NCGR,
		NARC_field_encounteffect_cutin_gym03_NSCR,
		0,
	},
	{
		214*FX32_ONE,			// 動さ完了X座標
		LEADER12_01,
		TRTYPE_LEADER12,			// リーダータイプ
		ENC_OAM_TR_CHAR_CUT_CX,	// OAMキャラのオフセット
		NARC_field_encounteffect_trgs_face12_NCLR,
		NARC_field_encounteffect_trgs_face12_NCGR,
		NARC_field_encounteffect_trgs_face12_NCER,
		NARC_field_encounteffect_trgs_face12_NANR,
		NARC_field_encounteffect_cutin_gym04_NCLR,
		NARC_field_encounteffect_cutin_gym04_NCGR,
		NARC_field_encounteffect_cutin_gym04_NSCR,
		0,
	},
	{
		214*FX32_ONE,			// 動さ完了X座標
		LEADER13_01,
		TRTYPE_LEADER13,			// リーダータイプ
		ENC_OAM_TR_CHAR_CUT_CX,	// OAMキャラのオフセット
		NARC_field_encounteffect_trgs_face13_NCLR,
		NARC_field_encounteffect_trgs_face13_NCGR,
		NARC_field_encounteffect_trgs_face13_NCER,
		NARC_field_encounteffect_trgs_face13_NANR,
		NARC_field_encounteffect_cutin_gym05_NCLR,
		NARC_field_encounteffect_cutin_gym05_NCGR,
		NARC_field_encounteffect_cutin_gym05_NSCR,
		0,
	},
	{
		214*FX32_ONE,			// 動さ完了X座標
		LEADER14_01,
		TRTYPE_LEADER14,			// リーダータイプ
		ENC_OAM_TR_CHAR_CUT_CX,	// OAMキャラのオフセット
		NARC_field_encounteffect_trgs_face14_NCLR,
		NARC_field_encounteffect_trgs_face14_NCGR,
		NARC_field_encounteffect_trgs_face14_NCER,
		NARC_field_encounteffect_trgs_face14_NANR,
		NARC_field_encounteffect_cutin_gym06_NCLR,
		NARC_field_encounteffect_cutin_gym06_NCGR,
		NARC_field_encounteffect_cutin_gym06_NSCR,
		0,
	},
	{
		214*FX32_ONE,			// 動さ完了X座標
		LEADER15_01,
		TRTYPE_LEADER15,			// リーダータイプ
		ENC_OAM_TR_CHAR_CUT_CX,	// OAMキャラのオフセット
		NARC_field_encounteffect_trgs_face15_NCLR,
		NARC_field_encounteffect_trgs_face15_NCGR,
		NARC_field_encounteffect_trgs_face15_NCER,
		NARC_field_encounteffect_trgs_face15_NANR,
		NARC_field_encounteffect_cutin_gym07_NCLR,
		NARC_field_encounteffect_cutin_gym07_NCGR,
		NARC_field_encounteffect_cutin_gym07_NSCR,
		0,
	},
	{
		214*FX32_ONE,			// 動さ完了X座標
		OLDRIVAL_01,
		TRTYPE_OLDRIVAL,		// リーダータイプ
		ENC_OAM_TR_CHAR_CUT_CX,	// OAMキャラのオフセット
		NARC_field_encounteffect_trgs_oldrival_NCLR,
		NARC_field_encounteffect_trgs_oldrival_NCGR,
		NARC_field_encounteffect_trgs_oldrival_NCER,
		NARC_field_encounteffect_trgs_oldrival_NANR,
		NARC_field_encounteffect_cutin_gym08_NCLR,
		NARC_field_encounteffect_cutin_gym08_NCGR,
		NARC_field_encounteffect_cutin_gym08_NSCR,
		0,
	},
};

// 09.03.18 Rival add by hosaka genya
static const ENCOUNT_SPTR_GYM_PARAM ENCOUNT_SPTR_RivalDef =
{
		214*FX32_ONE,			// 動さ完了X座標
		RIVAL_01,	// ダミー
		TRTYPE_RIVAL,			// リーダータイプ
		ENC_OAM_TR_CHAR_CUT_CX,	// OAMキャラのオフセット
		NARC_field_encounteffect_trgs_rival_NCLR,
		NARC_field_encounteffect_rival_face_NCGR,
		NARC_field_encounteffect_rival_face_NCER,
		NARC_field_encounteffect_rival_face_NANR,
		NARC_field_encounteffect_cutin_rival_NCLR,
		NARC_field_encounteffect_cutin_rival_NCGR,
		NARC_field_encounteffect_cutin_rival_NSCR,
		0,
};

//-------------------------------------
//	四天王　チャンピオン　リーダー
//=====================================
// シーケンス
enum{
	ENCOUNT_SPTR_CHANP_START,
	ENCOUNT_SPTR_CHANP_START2,
	ENCOUNT_SPTR_CHANP_FLASH_INI,
	ENCOUNT_SPTR_CHANP_FLASH_WAIT,
	ENCOUNT_SPTR_CHANP_GPRINT_WAIT,
	ENCOUNT_SPTR_CHANP_HERO_IN,
	ENCOUNT_SPTR_CHANP_HERO_INWAIT,
	ENCOUNT_SPTR_CHANP_HERO_FLASHOUT,
	ENCOUNT_SPTR_CHANP_HERO_FLASHOUTWAIT,
	ENCOUNT_SPTR_CHANP_HERO_FLASHIN,
	ENCOUNT_SPTR_CHANP_HERO_FLASHINWAIT,
	ENCOUNT_SPTR_CHANP_BT_IN,
	ENCOUNT_SPTR_CHANP_BT_INWAIT,
	ENCOUNT_SPTR_CHANP_WIPEWAIT,
	ENCOUNT_SPTR_CHANP_END,
};
// OAMデータ
// アクターデータ数
#define ENCOUNT_SPTR_CHANP_CELLACT_NUM		( 10 )	// ワーク数
#define ENCOUNT_SPTR_CHANP_CELL_NUM		( 4 )	// ワーク数
#define ENCOUNT_SPTR_CHANP_CELL_RES_NUM	( 4 )	// リソース数
#define ENCOUNT_SPTR_CHANP_CELL_CONT_ID	( 600000 )
#define ENCOUNT_SPTR_CHANP_CELL_SCALE	( FX32_CONST( 2.0f ) )
#define ENCOUNT_SPTR_CHANP_LEADER_DRAW_BOTTOM	( 30 )	// 下はこのサイズまで表示する
#define ENCOUNT_SPTR_CHANP_COLOR_FADE	( GX_RGB( 0,0,0 ) )
#define ENCOUNT_SPTR_CHANP_COLOR_FADE_EVY	(14)

// 動さパラメータ	（触ってよい部分）
// 主人公動さ
#define ENCOUNT_SPTR_CHANP_HERO_MOVE_SX		( -128*FX32_ONE )	// 主人公　登場開始X座標
#define ENCOUNT_SPTR_CHANP_HERO_MOVE_SS		( 80*FX32_ONE )		// 主人公　登場初速度
#define ENCOUNT_SPTR_CHANP_HERO_MOVE_EX		( 56*FX32_ONE )		// 主人公　登場終了X座標
#define ENCOUNT_SPTR_CHANP_HERO_Y			( 92*FX32_ONE )		// 主人公　Y座標
#define ENCOUNT_SPTR_CHANP_HERO_Y_WAKU_OFS	( 4*FX32_ONE )		// 枠が離れる座標
#define ENCOUNT_SPTR_CHANP_HERO_X_WAKU_OFS	( 16*FX32_ONE )		// 枠が離れる座標
#define ENCOUNT_SPTR_CHANP_HERO_MOVE_SYNC	( 6 )				// 主人公　登場シンク数
#define ENCOUNT_SPTR_CHANP_HERO_FLASHOUT_SYNC	( 3 )		// 主人公フラッシュアウト　シンク数
#define ENCOUNT_SPTR_CHANP_HERO_FLASHIN_SYNC	( 6 )		// 主人公フラッシュイン　シンク数
#define ENCOUNT_SPTR_CHANP_HERO_EFFECT_WAIT		( 3 )

// 四天王　チャンピオン動さ
#define ENCOUNT_SPTR_CHANP_ENEMY_MOVE_SX		( 384*FX32_ONE )	// 主人公　登場開始X座標
#define ENCOUNT_SPTR_CHANP_ENEMY_MOVE_SS		( -80*FX32_ONE )		// 主人公　登場初速度
#define ENCOUNT_SPTR_CHANP_ENEMY_MOVE_EX		( 200*FX32_ONE )		// 主人公　登場終了X座標
#define ENCOUNT_SPTR_CHANP_ENEMY_Y			( 92*FX32_ONE )	// 主人公　Y座標
#define ENCOUNT_SPTR_CHANP_ENEMY_Y_WAKU_OFS	( 4*FX32_ONE )		// 枠が離れる座標
#define ENCOUNT_SPTR_CHANP_ENEMY_X_WAKU_OFS	( -16*FX32_ONE )		// 枠が離れる座標
#define ENCOUNT_SPTR_CHANP_ENEMY_MOVE_SYNC	( 6 )				// 主人公　登場シンク数

//VSアニメ
#define ENCOUNT_SPTR_CHANP_VSMARK_X		( FX32_CONST( 128 ) )	// VSMARKの位置
#define ENCOUNT_SPTR_CHANP_VSMARK_Y		( FX32_CONST( 96 ) )	// VSMARKの位置

// 名前
#define ENCOUNT_SPTR_CHANP_TRNAME_X		( 21 )	// トレーナー名Xキャラ座標
#define ENCOUNT_SPTR_CHANP_TRNAME_Y		( 13 )	// トレーナー名Yキャラ座標
#define ENCOUNT_SPTR_CHANP_TRNAME_SIZX	( 11 )	// トレーナー名BMPXキャラサイズ
#define ENCOUNT_SPTR_CHANP_TRNAME_SIZY	( 2 )	// トレーナー名BMPYキャラサイズ
#define ENCOUNT_SPTR_CHANP_TRNAME_CGX	( 1 )
#define ENCOUNT_SPTR_CHANP_TRNAME_PAL	( 2 )
#define ENCOUNT_SPTR_CHANP_TRNAME_COL	( GF_PRINTCOLOR_MAKE( 1, 2, 0 ) )

// さらにぶつかり合うところの動作
#define ENCOUNT_SPTR_CHANP_BT_IN_WAIT			( 8 )	// 動作開始までのウエイト
#define ENCOUNT_SPTR_CHANP_BT_IN_MOVE_SX		( 0 )	//
#define ENCOUNT_SPTR_CHANP_BT_IN_MOVE_EX		( -FX32_CONST(2) )	// 移動する値
#define ENCOUNT_SPTR_CHANP_BT_IN_MOVE_SSX		( 0 )	// 初速度
#define ENCOUNT_SPTR_CHANP_BT_IN_MOVE_SY		( 0 )	//
#define ENCOUNT_SPTR_CHANP_BT_IN_MOVE_EY		( -FX32_CONST(2) )	// 移動する値
#define ENCOUNT_SPTR_CHANP_BT_IN_MOVE_SSY		( 0 )	// 初速度
#define ENCOUNT_SPTR_CHANP_BT_IN_MOVE_SYNC		( 32 )
#define ENCOUNT_SPTR_CHANP_BT_IN_MOVE_SYNC_C	( 9 )	// シロナ
#define ENCOUNT_SPTR_CHANP_BT_IN_MOVE_CHG		( 2	)	// 動く方向を変更するタイミング

// 最後の白くなるとこ
#define ENCOUNT_SPTR_CHANP_WIPE_OUT_SYNC		( 16 )	// ワイプアウトシンク数
#define ENCOUNT_SPTR_CHANP_OMA_MOVE_X			( FX32_CONST( 192.0f ) )	// OAM動さ距離
#define ENCOUNT_SPTR_CHANP_OMA_MOVE_Y			( FX32_CONST( 192.0f ) )	// OAM動さ距離
#define ENCOUNT_SPTR_CHANP_OAM_MOVE_XSS			( FX32_CONST( 24.0f ) )	// OAM動さ初速度
#define ENCOUNT_SPTR_CHANP_OAM_MOVE_YSS			( FX32_CONST( 24.0f ) )	// OAM動さ初速度
#define ENCOUNT_SPTR_CHANP_WIPE_OUT_SYNC_WIPE	( 8 )	// ワイプアウトシンク数

//=============================================================================
/**
 *							プロトタイプ宣言
 */
//=============================================================================

// それぞれの定数
typedef struct{
	u16 enemy_ncl;
	u8	waku_oam_cl;
	u8	bt_in_move_sync;
	u16	enemy_tr_type;
	u16 tr_no;
} ENCOUNT_SPTR_CHANP_PARAM;

static const ENCOUNT_SPTR_CHANP_PARAM EncountSpTr_ChanpParam[ 5 ] = {
	{	// 四天王１
		NARC_field_encounteffect_trgs_face_bigfour1_NCLR,
		NARC_field_encounteffect_cutin_chanpion00_NCLR,
		ENCOUNT_SPTR_CHANP_BT_IN_MOVE_SYNC,
		TRTYPE_BIGFOUR1,
		BIGFOUR1_01
	},
	{	// 四天王２
		NARC_field_encounteffect_trgs_face_bigfour2_NCLR,
		NARC_field_encounteffect_cutin_chanpion01_NCLR,
		ENCOUNT_SPTR_CHANP_BT_IN_MOVE_SYNC,
		TRTYPE_BIGFOUR2,
		BIGFOUR2_01
	},
	{	// 四天王３
		NARC_field_encounteffect_trgs_face_bigfour3_NCLR,
		NARC_field_encounteffect_cutin_chanpion02_NCLR,
		ENCOUNT_SPTR_CHANP_BT_IN_MOVE_SYNC,
		TRTYPE_BIGFOUR3,
		BIGFOUR3_01
	},
	{	// 四天王４
		NARC_field_encounteffect_trgs_face_bigfour4_NCLR,
		NARC_field_encounteffect_cutin_chanpion03_NCLR,
		ENCOUNT_SPTR_CHANP_BT_IN_MOVE_SYNC,
		TRTYPE_BIGFOUR4,
		BIGFOUR4_01
	},
	{	// チャンピオン
		NARC_field_encounteffect_trgs_face_champion_NCLR,
		NARC_field_encounteffect_cutin_chanpion04_NCLR,
		ENCOUNT_SPTR_CHANP_BT_IN_MOVE_SYNC_C,
		TRTYPE_CHAMPION,
		CHAMPION_01
	},

};

//=============================================================================
/**
 *								構造体定義
 */
//=============================================================================

//-------------------------------------
///	VSアニメ
//=====================================
typedef struct {
	s16 timing;
	s16 movenum;
	CLACT_WORK_PTR vs[ ENCOUNT_SPTR_GYM_VSOAM_NUM ];
	ENC_MOVE_WORK_FX vsscale[ ENCOUNT_SPTR_GYM_VSOAM_NUM ];
} ENCOUNT_SPTR_GYM_VSANM;

//-------------------------------------
//	ジムリーダー
//=====================================
typedef struct {
	ENC_ADDMOVE_WORK_FX oam_move_x;
	ENC_MOVE_WORK flash;
	ENC_MOVE_WORK_FX scale;

	ENC_HB_BG_WND_ZIGUZAGU* p_ziguzagu;

	ENC_CLACT_SYS	clact_sys;
	ENC_CLACT_RES_WORK clact_res[2];
	CLACT_WORK_PTR clact;
	ENCOUNT_SPTR_GYM_VSANM vsanm;
	ENC_WND_SETPOSITION wnd_posi;
	ENC_BG_SET_AFFINEPARAM bg_affine;

	GF_BGL_BMPWIN trnamewin;

	BOOL bg_auto_move;
	s32 auto_move_x;

	s32 wait;
} ENCOUNT_SPTR_GYM;

//-------------------------------------
//	四天王　チャンピオン
//=====================================
typedef struct {
	ENC_ADDMOVE_WORK_FX oam_move_x;
	ENC_ADDMOVE_WORK_FX oam_move_y;
	ENC_ADDMOVE_WORK_FX enemy_oam_move_x;
	ENC_MOVE_WORK flash;

	ENC_CLACT_SYS	clact_sys;
	ENC_CLACT_RES_WORK clact_res[ENCOUNT_SPTR_CHANP_CELL_RES_NUM];
	CLACT_WORK_PTR clact[ENCOUNT_SPTR_CHANP_CELL_NUM];
	VecFx32			pos_hero;
	VecFx32			pos_enemy;

	// VSアニメ
	ENCOUNT_SPTR_GYM_VSANM vsanm;

	// トレーナ名用ビットマップ
	GF_BGL_BMPWIN trnamewin;

	u32 hero_type;	// 主人公タイプ
	u32 hero_nclr;

	s32 wait;
	s32 count;
} ENCOUNT_SPTR_CHANP;


//----------------------------------------------------------------------------
/**
 *	@brief	VSアニメ	初期化
 *
 *	@param	task_w		タスクワーク
 *	@param	heapID		ヒープID
 */
//-----------------------------------------------------------------------------
static void EncountEffect_SpTr_VsAnmInit( ENCOUNT_SPTR_GYM_VSANM* p_wk, ENC_CLACT_SYS* p_clset, ENC_CLACT_RES_WORK* p_res, fx32 x, fx32 y, u32 heapID )
{
	int i;

	p_wk->timing = 0;
	p_wk->movenum = 0;

	for( i=0; i<ENCOUNT_SPTR_GYM_VSOAM_NUM; i++ ){
		p_wk->vs[i] = ENC_CLACT_Add(
				p_clset, p_res,
				x,
				y,0, 0);
		CLACT_SetDrawFlag( p_wk->vs[i], FALSE );
		CLACT_SetAnmFlag( p_wk->vs[i], 1 );
		if( i!=ENCOUNT_SPTR_GYM_VSOAM ){	// 最後の１つが文字
			CLACT_SetAffineParam( p_wk->vs[i], CLACT_AFFINE_DOUBLE );
			CLACT_AnmChg( p_wk->vs[i], 1 );
			// 拡大縮小データ作成
			ENC_MoveReqFx( &p_wk->vsscale[i],
					FX32_CONST(2),
					FX32_CONST(1),
					ENCOUNT_SPTR_GYM_VSANMSYNC );
		}else{
			// 拡大縮小データ作成
			ENC_MoveReqFx( &p_wk->vsscale[i],
					FX32_CONST(1),
					FX32_CONST(1),
					ENCOUNT_SPTR_GYM_VSANMSYNC );
		}

	}
}

static void EncountEffect_SpTr_VsAnmExit( ENCOUNT_SPTR_GYM_VSANM* p_wk )
{
	int i;
	for( i=0; i<ENCOUNT_SPTR_GYM_VSOAM_NUM; i++ ){
		CLACT_Delete( p_wk->vs[i] );
	}
}

//----------------------------------------------------------------------------
/**
 *	@brief	VSアニメ	メイン
 *
 *	@param	task_w		タスクワーク
 *
 *	@retval	TRUE	完了
 *	@retval	FALSE	途中
 */
//-----------------------------------------------------------------------------
static BOOL EncountEffect_SpTr_VsAnmMain( ENCOUNT_SPTR_GYM_VSANM* p_wk )
{
	int i;
	BOOL result;
	BOOL ret = TRUE;
	VecFx32 scale;

	// みんなを動かすタイミングを制御
	if( p_wk->movenum < ENCOUNT_SPTR_GYM_VSOAM_NUM ){
		ret = FALSE;	// まだ全部動ききってない
		p_wk->timing--;
		if( p_wk->timing <= 0 ){
			p_wk->timing = ENCOUNT_SPTR_GYM_VSANMTIMING;
			p_wk->movenum ++;
		}
	}

	// 動かしていい人数分動かす
	for( i=0; i<p_wk->movenum; i++ ){
		result = ENC_MoveMainFx( &p_wk->vsscale[i] );

		scale = ENC_MakeVec(
				p_wk->vsscale[i].x,
				p_wk->vsscale[i].x, p_wk->vsscale[i].x );
		CLACT_SetScale( p_wk->vs[i], &scale );
		CLACT_SetDrawFlag( p_wk->vs[i], TRUE );
		// 1つでもまだ動ききっていないのがあるなら途中
		if( result == FALSE ){
			ret = FALSE;
		}else{
			// 本体以外を非表示
			if( i != ENCOUNT_SPTR_GYM_VSOAM ) {
				CLACT_SetDrawFlag( p_wk->vs[i], FALSE );
			}
		}
	}

	return ret;
}


//----------------------------------------------------------------------------
/**
 *	@brief	トレーナータイプから名前を取得する
 *
 *	@param	type		トレーナータイプ
 *	@param	heapID		ヒープID
 *
 *	@return	名前	破棄が必要　STRBUF_Delete()
 */
//-----------------------------------------------------------------------------
static STRBUF* EncountEffect_SpTr_Gym_TrTypeNameGet( u32 type, u32 heapID )
{
	WORDSET* p_wordset;
	MSGDATA_MANAGER* p_man;
	STRBUF* p_str;
	STRBUF* p_tmp;

#ifdef PLATINUM_MERGE_MSG
	p_man = MSGMAN_Create(MSGMAN_TYPE_DIRECT, ARC_MSG, NARC_msg_encount_effect_dat, heapID);
	p_wordset = WORDSET_Create( heapID );
	p_str = STRBUF_Create( 128, heapID );
	p_tmp = STRBUF_Create( 128, heapID );
	MSGMAN_GetString( p_man, msg_00, p_tmp );
	WORDSET_RegisterTrainerName( p_wordset, 0, type );
	WORDSET_ExpandStr( p_wordset, p_str, p_tmp );

	MSGMAN_Delete( p_man );
	WORDSET_Delete( p_wordset );
	STRBUF_Delete( p_tmp );
	return p_str;
#endif

	return NULL;
}

// 09.03.18 add by hosaka genya
//-----------------------------------------------------------------------------
/**
 *	@brief	ライバルの名前を取得する
 *
 *	@param	SAVEDATA* svdata	セーブデータへのポインタ
 *	@param	heapID				ヒープID
 *
 *	@retval	名前	破棄が必要　STRBUF_Delete()
 */
//-----------------------------------------------------------------------------
static STRBUF* EncountEffect_SpTr_RivalNameGet( SAVEDATA* svdata, u32 heapID )
{
	WORDSET* p_wordset;
	MSGDATA_MANAGER* p_man;
	STRBUF* p_str;
	STRBUF* p_tmp;

	p_man = MSGMAN_Create(MSGMAN_TYPE_DIRECT, ARC_MSG, NARC_msg_encount_effect_dat, heapID);
	p_wordset = WORDSET_Create( heapID );
	p_str = STRBUF_Create( 128, heapID );
	p_tmp = STRBUF_Create( 128, heapID );
	MSGMAN_GetString( p_man, msg_00, p_tmp );
	WORDSET_RegisterRivalName( p_wordset, 0, svdata );
	WORDSET_ExpandStr( p_wordset, p_str, p_tmp );

	MSGMAN_Delete( p_man );
	WORDSET_Delete( p_wordset );
	STRBUF_Delete( p_tmp );
	return p_str;
}

//----------------------------------------------------------------------------
/**
 *	@brief	ジム専用エンカウントエフェクト
 *
 *	@param	eew		エフェクトワーク
 *	@param	heapID	ヒープID
 *	@param	cp_def	デファイン定義
 *
 *	@retval	TRUE		終了
 *	@retval	FALSE		途中
 */
//-----------------------------------------------------------------------------
static BOOL EncountEffect_SpTr_GymMain( ENCOUNT_EFFECT_WORK *eew, u32 heapID, const ENCOUNT_SPTR_GYM_PARAM* cp_def )
{
	ENCOUNT_SPTR_GYM* task_w = eew->work;
	BOOL result;
	const VecFx32* cp_matrix;
	VecFx32 matrix;
	VecFx32 scale;
	int bottom_y;
	int i;
	STRBUF* p_str;

	switch( eew->seq ){
	case ENCOUNT_SPTR_GYM_START:
		eew->work = sys_AllocMemory( heapID, sizeof(ENCOUNT_SPTR_GYM) );
		memset( eew->work, 0, sizeof(ENCOUNT_SPTR_GYM) );
		task_w = eew->work;

#ifdef PLATINUM_MERGE_MSG
		// パレット読み込み
		ArcUtil_HDL_PalSet( eew->p_handle,
				NARC_field_encounteffect_cutin_gym_font_NCLR,
				PALTYPE_MAIN_BG, ENCOUNT_SPTR_GYM_TRNAME_PAL*0x20, 0x20, heapID );

#endif
		// トレーナー名表示用ビットマップ作成
		GF_Disp_GX_VisibleControl(GX_PLANEMASK_BG2, VISIBLE_OFF);
		GF_BGL_BmpWinAdd( eew->fsw->bgl, &task_w->trnamewin,
				GF_BGL_FRAME2_M, ENCOUNT_SPTR_GYM_TRNAME_X, ENCOUNT_SPTR_GYM_TRNAME_Y,
				ENCOUNT_SPTR_GYM_TRNAME_SIZX, ENCOUNT_SPTR_GYM_TRNAME_SIZY,
				ENCOUNT_SPTR_GYM_TRNAME_PAL, ENCOUNT_SPTR_GYM_TRNAME_CGX );
		GF_BGL_BmpWinDataFill( &task_w->trnamewin, 0 );
		OS_TPrintf("load trname no :%d \n", cp_def->trno );

		// 09.03.18 add by hosaka genya
		// ライバルならセーブデータから取得
		if( cp_def->type == TRTYPE_RIVAL ) {
			p_str = EncountEffect_SpTr_RivalNameGet( eew->fsw->savedata, heapID );
		}else{
			p_str = EncountEffect_SpTr_Gym_TrTypeNameGet( cp_def->trno, heapID );
		}

		GF_STR_PrintColor( &task_w->trnamewin, FONT_SYSTEM,
                                       p_str, 0, 0, MSG_ALLPUT,
									   ENCOUNT_SPTR_GYM_TRNAME_COL, NULL);
		STRBUF_Delete( p_str );	// 破棄わすれ注意！


		// セルアクターセット作成
		ENC_CLACT_Init( &task_w->clact_sys, ENCOUNT_SPTR_GYM_CELL_NUM, ENCOUNT_SPTR_GYM_CELL_RES_NUM );

		// グラフィック設定
		ENC_CLACT_ResLoadEasy(
				eew->p_handle,
				&task_w->clact_sys,
				&task_w->clact_res[0],
				cp_def->nclr, 1,
				cp_def->ncgr,
				cp_def->ncer,
				cp_def->nanr,
				ENCOUNT_SPTR_GYM_CELL_CONT_ID
				);

		// VSグラフィック
		ENC_CLACT_ResLoadEasy(
				eew->p_handle,
				&task_w->clact_sys,
				&task_w->clact_res[1],
				NARC_field_encounteffect_cutin_gym_vs_NCLR, 1,
				NARC_field_encounteffect_cutin_gym_vs_NCGR,
				NARC_field_encounteffect_cutin_gym_vs_NCER,
				NARC_field_encounteffect_cutin_gym_vs_NANR,
				ENCOUNT_SPTR_GYM_CELL_CONT_ID + 1
				);

		// アクター登録
		task_w->clact = ENC_CLACT_Add(
				&task_w->clact_sys, &task_w->clact_res[0],
				ENCOUNT_SPTR_GYM_OAM_START_X,
				ENCOUNT_SPTR_GYM_OAM_START_Y,0, 0);
		CLACT_SetDrawFlag( task_w->clact, FALSE );
		EncountEffect_SpTr_VsAnmInit( &task_w->vsanm, &task_w->clact_sys, &task_w->clact_res[1], ENCOUNT_SPTR_GYM_VSMARK_X, ENCOUNT_SPTR_GYM_VSMARK_Y, heapID );
//		CLACT_SetAffineParam( task_w->clact, CLACT_AFFINE_DOUBLE );

		// カラーパレットを設定
//		ENC_CLACT_ResColorChange( task_w->clact, heapID, cp_def->type, ENCOUNT_SPTR_GYM_LEADER_COLOR_FADE_EVY, ENCOUNT_SPTR_GYM_LEADER_COLOR_FADE );
		EncountEffect_SPTR_ResColorChange( task_w->clact, heapID, cp_def->nclr, ENCOUNT_SPTR_GYM_LEADER_COLOR_FADE_EVY, ENCOUNT_SPTR_GYM_LEADER_COLOR_FADE );
		// ジムリーダーキャラクタパレット転送
//		ENC_CLACT_ResSetSoftSpriteDataTrOam( task_w->clact, heapID, cp_def->type, ENCOUNT_SPTR_GYM_LEADER_COLOR_FADE_EVY, ENCOUNT_SPTR_GYM_LEADER_COLOR_FADE, cp_def->tr_oam_chr_ofs_cx );

		// アフィンBG設定
//		ENC_BG_SetAffineCont( eew->fsw->bgl );

		// ジグザグウィンドウ初期化
		task_w->p_ziguzagu = ENC_BG_WndZiguzagu_Alloc();

		eew->seq ++;
		break;

	case ENCOUNT_SPTR_GYM_FLASH_INI:

		EncountFlashTask(MASK_MAIN_DISPLAY, 16, 16,  &eew->wait, 1);
		eew->seq++;
		break;

	case ENCOUNT_SPTR_GYM_FLASH_WAIT:
		if( eew->wait ){
			eew->seq++;
		}
		break;

	case ENCOUNT_SPTR_GYM_BG_IN:

		// BG設定
		ENC_BG_SetNormalBG(
				eew->p_handle,
				cp_def->bg_nscr,
				cp_def->bg_ncgr,
				cp_def->bg_nclr,
				0, 1,
				eew->fsw->bgl, GF_BGL_FRAME3_M );
		task_w->bg_auto_move = TRUE;	// BGAUTO動さ

		// ジグザグウィンドウスタート
		ENC_BG_WndZiguzagu_Start( eew, task_w->p_ziguzagu,
				ENCOUNT_SPTR_GYM_ZIGUZAGU_SYNC,
				ENCOUNT_SPTR_GYM_ZIGUZAGU_DOT,
				ENCOUNT_SPTR_GYM_ZIGUZAGU_WIDTH,
				ENCOUNT_SPTR_GYM_ZIGUZAGU_IN_WND,
				ENCOUNT_SPTR_GYM_ZIGUZAGU_OUT_WND );
/*
		// BGAUTO動さのために拡大パラメータをここで作成
		ENC_MoveReqFx( &task_w->scale,
				ENCOUNT_SPTR_GYM_SCALE_S,
				ENCOUNT_SPTR_GYM_SCALE_E,
				ENCOUNT_SPTR_GYM_FADEOUT_SYNC );
//*/

		// プライオリティ設定
		GF_BGL_PrioritySet( GF_BGL_FRAME2_M, 0 );	// 名前
		GF_BGL_PrioritySet( GF_BGL_FRAME3_M, 1 );	// ジグザグ
		GF_BGL_PrioritySet( GF_BGL_FRAME0_M, 2 );	// フィールド

		// BG面表示
		GF_Disp_GX_VisibleControl(GX_PLANEMASK_BG3, VISIBLE_ON);
		GF_Disp_GX_VisibleControl(GX_PLANEMASK_BG1, VISIBLE_OFF);

		eew->seq++;
		break;

	case ENCOUNT_SPTR_GYM_BG_INWAIT:

		if( ENC_HBlankEndCheck( eew ) ){
			eew->seq++;
			// ウィンドウエフェクト破棄
			ENC_BG_WndZiguzagu_Delete( task_w->p_ziguzagu );

			task_w->wait = ENCOUNT_SPTR_GYM_BG_AFTER_WAIT;
		}
		break;

	case ENCOUNT_SPTR_GYM_VS_ANMWAIT:

		task_w->wait --;
		if( task_w->wait >= 0 ){
			break;
		}
		GF_Disp_GX_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );

		// VSを出す
		result = EncountEffect_SpTr_VsAnmMain( &task_w->vsanm );
		if( result == TRUE ){
			eew->seq++;
		}
		break;


	case ENCOUNT_SPTR_GYM_OAM_IN:

#if 0
		// ジムリーダー基本拡大値設定
		scale = ENC_MakeVec(
				ENCOUNT_SPTR_GYM_LEADER_SCALE_DEF,
				ENCOUNT_SPTR_GYM_LEADER_SCALE_DEF, 0 );
		CLACT_SetScale( task_w->clact, &scale );

		// 囲いウィンドウ設定
		ENC_WND_SetScaleWnd(
				ENCOUNT_SPTR_GYM_OAM_START_Y,
				ENCOUNT_SPTR_GYM_BG_CY+ENCOUNT_SPTR_GYM_LEADER_DRAW_BOTTOM,
				ENCOUNT_SPTR_GYM_LEADER_SCALE_DEF,
				64, 0, &task_w->wnd_posi );
		G2_SetWnd0InsidePlane( GX_WND_PLANEMASK_BG0|GX_WND_PLANEMASK_BG1|GX_WND_PLANEMASK_BG2|GX_WND_PLANEMASK_BG3|GX_WND_PLANEMASK_OBJ, TRUE );
		G2_SetWndOutsidePlane( GX_WND_PLANEMASK_BG0|GX_WND_PLANEMASK_BG1|GX_WND_PLANEMASK_BG2|GX_WND_PLANEMASK_BG3, TRUE );
		GX_SetVisibleWnd(GX_WNDMASK_W0);
#endif

		ENC_AddMoveReqFx( &task_w->oam_move_x,
				ENCOUNT_SPTR_GYM_OAM_START_X,
				cp_def->end_x,
				ENCOUNT_SPTR_GYM_OAM_X_SS,
				ENCOUNT_SPTR_GYM_OAM_MOVE_SYNC );
		CLACT_SetDrawFlag( task_w->clact, TRUE );
		CLACT_BGPriorityChg( task_w->clact, 1 );

		matrix = ENC_MakeVec(
				task_w->oam_move_x.x,
				ENCOUNT_SPTR_GYM_OAM_START_Y, 0 );
		CLACT_SetMatrix( task_w->clact, &matrix );

		eew->seq++;
		break;

	case ENCOUNT_SPTR_GYM_OAM_INWAIT:

		result = ENC_AddMoveMainFx( &task_w->oam_move_x );
		matrix = ENC_MakeVec(
				task_w->oam_move_x.x,
				ENCOUNT_SPTR_GYM_OAM_START_Y, 0 );
		CLACT_SetMatrix( task_w->clact, &matrix );

#if 0
		// 囲いウィンドウ設定	OAMは反映が1シンク遅い
		cp_matrix = CLACT_GetMatrix( task_w->clact );
		ENC_WND_SetScaleWnd(
				cp_matrix->y,
				ENCOUNT_SPTR_GYM_BG_CY+ENCOUNT_SPTR_GYM_LEADER_DRAW_BOTTOM,
				ENCOUNT_SPTR_GYM_LEADER_SCALE_DEF,
				64, 0, &task_w->wnd_posi);
#endif

		if( result == TRUE ){
			eew->seq++;
		}
		break;

	case ENCOUNT_SPTR_GYM_OAM_FLASH_OUT:
		ENC_MoveReq( &task_w->flash, 0, 16, ENCOUNT_SPTR_GYM_FLASHOUT_SYNC );
		task_w->wait = ENCOUNT_SPTR_GYM_BG_AFTER_WAIT;
		eew->seq++;
		break;

	case ENCOUNT_SPTR_GYM_OAM_FLASH_OUT_WAIT:
		task_w->wait --;
		if( task_w->wait >= 0 ){
			break;
		}

		result = ENC_MoveMain( &task_w->flash );
		ENC_SetMasterBrightnessVblank( &task_w->flash.x );
		if( result == TRUE ){

			// OAMのカラーパレット変更
//			ENC_CLACT_ResColorChange( task_w->clact, heapID, cp_def->type, 0, ENCOUNT_SPTR_GYM_LEADER_COLOR_FADE );
			EncountEffect_SPTR_ResColorChange( task_w->clact, heapID, cp_def->nclr, 0, ENCOUNT_SPTR_GYM_LEADER_COLOR_FADE );

			// ３D面にブライトネスをカケル（GYMで半透明は使ってないだろうということで半透明つかっちゃいます）
			SetBrightness( ENCOUNT_SPTR_GYM_3DAREA_BRIGHTNESS,
					PLANEMASK_BG0|PLANEMASK_BD, MASK_MAIN_DISPLAY );

			//　文字を出す	ジムリーダーOAMの位置を基準に出す
			GF_BGL_ScrollReq( eew->fsw->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_SET, -((task_w->oam_move_x.x>>FX32_SHIFT) + ENCOUNT_SPTR_GYM_TRNAME_OFS_X) );
			GF_Disp_GX_VisibleControl( GX_PLANEMASK_BG2, VISIBLE_ON );
			eew->seq++;
		}
		break;

	case ENCOUNT_SPTR_GYM_OAM_FLASH_IN:
		ENC_MoveReq( &task_w->flash, 16, 0, ENCOUNT_SPTR_GYM_FLASHIN_SYNC );
		eew->seq++;
		break;

	case ENCOUNT_SPTR_GYM_OAM_FLASH_IN_WAIT:
		result = ENC_MoveMain( &task_w->flash );
		ENC_SetMasterBrightnessVblank( &task_w->flash.x );
		if( result == TRUE ){
			eew->seq++;
			task_w->wait = ENCOUNT_SPTR_GYM_FLASH_AFTER_WAIT;
		}
		break;

	case ENCOUNT_SPTR_GYM_WAIT:
		task_w->wait --;
		if( task_w->wait < 0 ){
			eew->seq ++;
		}
		break;

	case ENCOUNT_SPTR_GYM_WIPE:

		// ホワイトアウト
		WIPE_SYS_Start( WIPE_PATTERN_M, WIPE_TYPE_FADEOUT, WIPE_TYPE_FADEOUT, WIPE_FADE_WHITE, ENCOUNT_SPTR_GYM_FADEOUT_SYNC, 1, HEAPID_FIELD );
		eew->seq ++;
		break;

	case ENCOUNT_SPTR_GYM_WIPEWAIT:
#if 0
		ENC_MoveMainFx( &task_w->scale );
		// FX32_ONE引くのは、scaleの開始が1からだから
		scale = ENC_MakeVec(
				ENCOUNT_SPTR_GYM_LEADER_SCALE_DEF + task_w->scale.x - FX32_ONE,
				ENCOUNT_SPTR_GYM_LEADER_SCALE_DEF + task_w->scale.x - FX32_ONE, 0 );
		CLACT_SetScale( task_w->clact, &scale );

		cp_matrix = CLACT_GetMatrix( task_w->clact );

		// 底辺の座標を求める
		bottom_y = ENC_WND_SetScaleWndToolMakeBottomY( task_w->scale.x, ENCOUNT_SPTR_GYM_BG_CY, ENCOUNT_SPTR_GYM_LEADER_DRAW_BOTTOM );
		// 囲いウィンドウ設定
		ENC_WND_SetScaleWnd(
				cp_matrix->y,
				bottom_y,
				scale.y, 64, 0, &task_w->wnd_posi);
#endif

		if( WIPE_SYS_EndCheck() ) {
			eew->seq ++;
		}
		break;

	case ENCOUNT_SPTR_GYM_END:
		WIPE_SetBrightness( WIPE_DISP_SUB, WIPE_FADE_WHITE );

		if(eew->end != NULL){
			*(eew->end) = TRUE;		// タスク終了を報告
		}
		// OAM破棄
		CLACT_Delete( task_w->clact );
		EncountEffect_SpTr_VsAnmExit( &task_w->vsanm );
		ENC_CLACT_ResDeleteEasy( &task_w->clact_sys, &task_w->clact_res[0] );
		ENC_CLACT_ResDeleteEasy( &task_w->clact_sys, &task_w->clact_res[1] );
		ENC_CLACT_Delete( &task_w->clact_sys );

		// BMP
		GF_BGL_BmpWinDel( &task_w->trnamewin );

		// ウィンドウ破棄
		GX_SetVisibleWnd(GX_WNDMASK_NONE);

		// ブライトネスはき
		SetBrightness( BRIGHTNESS_NORMAL,
				PLANEMASK_NONE, MASK_MAIN_DISPLAY );

		// スクロール
		GF_BGL_ScrollSet( eew->fsw->bgl, GF_BGL_FRAME2_M, GF_BGL_SCROLL_X_SET, 0 );

		return TRUE;
	}

	if( task_w->bg_auto_move == TRUE ){
		GF_BGL_ScrollReq( eew->fsw->bgl, GF_BGL_FRAME3_M,
				GF_BGL_SCROLL_X_SET, task_w->auto_move_x );

		task_w->auto_move_x = (task_w->auto_move_x + ENCOUNT_SPTR_GYM_BG_AUTOMOVE_X) % 512;
	}

	if( eew->seq != ENCOUNT_SPTR_GYM_END ){
		CLACT_Draw( task_w->clact_sys.cas );
	}

	return FALSE;
}


//----------------------------------------------------------------------------
/**
 *	@brief		各ジム
 */
//-----------------------------------------------------------------------------
void EncountEffect_SPTR_IwaGym(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_GymMain( eew, HEAPID_FIELD, &ENCOUNT_SPTR_GymDef[0] );
	if( result == TRUE ){
		ENC_End( eew, tcb );
	}
}
void EncountEffect_SPTR_KusaGym(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_GymMain( eew, HEAPID_FIELD, &ENCOUNT_SPTR_GymDef[1] );
	if( result == TRUE ){
		ENC_End( eew, tcb );
	}
}
void EncountEffect_SPTR_MizuGym(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_GymMain( eew, HEAPID_FIELD, &ENCOUNT_SPTR_GymDef[2] );
	if( result == TRUE ){
		ENC_End( eew, tcb );
	}
}
void EncountEffect_SPTR_KakutouGym(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_GymMain( eew, HEAPID_FIELD, &ENCOUNT_SPTR_GymDef[3] );
	if( result == TRUE ){
		ENC_End( eew, tcb );
	}
}
void EncountEffect_SPTR_GoosutoGym(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_GymMain( eew, HEAPID_FIELD, &ENCOUNT_SPTR_GymDef[4] );
	if( result == TRUE ){
		ENC_End( eew, tcb );
	}
}
void EncountEffect_SPTR_KooriGym(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_GymMain( eew, HEAPID_FIELD, &ENCOUNT_SPTR_GymDef[5] );
	if( result == TRUE ){
		ENC_End( eew, tcb );
	}
}
void EncountEffect_SPTR_HaganeGym(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_GymMain( eew, HEAPID_FIELD, &ENCOUNT_SPTR_GymDef[6] );
	if( result == TRUE ){
		ENC_End( eew, tcb );
	}
}
void EncountEffect_SPTR_DenkiGym(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_GymMain( eew, HEAPID_FIELD, &ENCOUNT_SPTR_GymDef[7] );
	if( result == TRUE ){
		ENC_End( eew, tcb );
	}
}

// GYM カントー
void EncountEffect_SPTR_Takeshi(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_GymMain( eew, HEAPID_FIELD, &ENCOUNT_SPTR_GymDef[8] );
	if( result == TRUE ){ ENC_End( eew, tcb ); }
}

void EncountEffect_SPTR_Kasumi(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_GymMain( eew, HEAPID_FIELD, &ENCOUNT_SPTR_GymDef[9] );
	if( result == TRUE ){ ENC_End( eew, tcb ); }
}

void EncountEffect_SPTR_Mathisu(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_GymMain( eew, HEAPID_FIELD, &ENCOUNT_SPTR_GymDef[10] );
	if( result == TRUE ){ ENC_End( eew, tcb ); }
}

void EncountEffect_SPTR_Erika(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_GymMain( eew, HEAPID_FIELD, &ENCOUNT_SPTR_GymDef[11] );
	if( result == TRUE ){ ENC_End( eew, tcb ); }
}

void EncountEffect_SPTR_Anzu(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_GymMain( eew, HEAPID_FIELD, &ENCOUNT_SPTR_GymDef[12] );
	if( result == TRUE ){ ENC_End( eew, tcb ); }
}

void EncountEffect_SPTR_Natsume(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_GymMain( eew, HEAPID_FIELD, &ENCOUNT_SPTR_GymDef[13] );
	if( result == TRUE ){ ENC_End( eew, tcb ); }
}

void EncountEffect_SPTR_Katsura(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_GymMain( eew, HEAPID_FIELD, &ENCOUNT_SPTR_GymDef[14] );
	if( result == TRUE ){ ENC_End( eew, tcb ); }
}

void EncountEffect_SPTR_Green(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_GymMain( eew, HEAPID_FIELD, &ENCOUNT_SPTR_GymDef[15] );
	if( result == TRUE ){ ENC_End( eew, tcb ); }
}

// ライバル
void EncountEffect_SPTR_Rival(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_GymMain( eew, HEAPID_FIELD, &ENCOUNT_SPTR_RivalDef );
	if( result == TRUE ){
		ENC_End( eew, tcb );
	}
}

//----------------------------------------------------------------------------
/**
 *	@brief	性別取得
 */
//-----------------------------------------------------------------------------
static u32 EncountEffect_SPTR_ChanpSexCheck( FIELDSYS_WORK* p_fsys )
{
	MYSTATUS* p_mystatus = SaveData_GetMyStatus( p_fsys->savedata );
	return MyStatus_GetMySex( p_mystatus );
}

//----------------------------------------------------------------------------
/**
 *	@brief	四天王　チャンピオン専用エンカウントエフェクト
 *
 *	@param	eew		エフェクトワーク
 *	@param	heapID	ヒープID
 *	@param	cp_def	デファイン定義
 *
 *	@retval	TRUE		終了
 *	@retval	FALSE		途中
 */
//-----------------------------------------------------------------------------
static BOOL EncountEffect_SpTr_ChanpMain( ENCOUNT_EFFECT_WORK *eew, u32 heapID, const ENCOUNT_SPTR_CHANP_PARAM* cp_def )
{
	ENCOUNT_SPTR_CHANP* task_w = eew->work;
	BOOL result, result2;
	VecFx32 matrix;
	VecFx32 scale;
	int i;
	fx32 dist;
	ENC_CLACT_RES_WORK* p_clact_res;
	int seq;

	switch( eew->seq ){
	case ENCOUNT_SPTR_CHANP_START:
		eew->work = sys_AllocMemory( heapID, sizeof(ENCOUNT_SPTR_CHANP) );
		memset( eew->work, 0, sizeof(ENCOUNT_SPTR_CHANP) );
		task_w = eew->work;

		// セルアクターセット作成
		ENC_CLACT_Init( &task_w->clact_sys, ENCOUNT_SPTR_CHANP_CELLACT_NUM, ENCOUNT_SPTR_CHANP_CELL_RES_NUM );

		// グラフィック設定
		// 主人公男女チェック
		if( EncountEffect_SPTR_ChanpSexCheck( eew->fsw ) == 0 ){
			// 男
			ENC_CLACT_ResLoadEasy(
					eew->p_handle,
					&task_w->clact_sys,
					&task_w->clact_res[0],
					NARC_field_encounteffect_trpl_boyface_NCLR, 1,
					NARC_field_encounteffect_trpl_boyface_NCGR,
					NARC_field_encounteffect_trpl_boyface_NCER,
					NARC_field_encounteffect_trpl_boyface_NANR,
					ENCOUNT_SPTR_CELL_CONT_ID
					);

			task_w->hero_type  = TRTYPE_BOY;
			task_w->hero_nclr  = NARC_field_encounteffect_trpl_boyface_NCLR;
		}else{
			// 女
			ENC_CLACT_ResLoadEasy(
					eew->p_handle,
					&task_w->clact_sys,
					&task_w->clact_res[0],
					NARC_field_encounteffect_trpl_girlface_NCLR, 1,
					NARC_field_encounteffect_trpl_girlface_NCGR,
					NARC_field_encounteffect_trpl_girlface_NCER,
					NARC_field_encounteffect_trpl_girlface_NANR,
					ENCOUNT_SPTR_CELL_CONT_ID
					);

			task_w->hero_type  = TRTYPE_GIRL;
			task_w->hero_nclr  = NARC_field_encounteffect_trpl_girlface_NCLR;
		}
		// 敵読み込み
		ENC_CLACT_ResLoadEasy(
				eew->p_handle,
				&task_w->clact_sys,
				&task_w->clact_res[1],
				cp_def->enemy_ncl, 1,
				cp_def->enemy_ncl+1,
				cp_def->enemy_ncl+2,
				cp_def->enemy_ncl+3,
				ENCOUNT_SPTR_CELL_CONT_ID + 1
				);

		// 背景読み込み
		ENC_CLACT_ResLoadEasy(
				eew->p_handle,
				&task_w->clact_sys,
				&task_w->clact_res[2],
				cp_def->waku_oam_cl, 0xC,
				NARC_field_encounteffect_cutin_chanpion00_NCGR,
				NARC_field_encounteffect_cutin_chanpion00_NCER,
				NARC_field_encounteffect_cutin_chanpion00_NANR,
				ENCOUNT_SPTR_CELL_CONT_ID + 2
				);

		// VSグラフィック
		ENC_CLACT_ResLoadEasy(
				eew->p_handle,
				&task_w->clact_sys,
				&task_w->clact_res[3],
				NARC_field_encounteffect_cutin_gym_vs_NCLR, 1,
				NARC_field_encounteffect_cutin_gym_vs_NCGR,
				NARC_field_encounteffect_cutin_gym_vs_NCER,
				NARC_field_encounteffect_cutin_gym_vs_NANR,
				ENCOUNT_SPTR_CELL_CONT_ID + 3
				);


		eew->seq ++;
		break;

	case ENCOUNT_SPTR_CHANP_START2:

		// アクター登録
		scale = ENC_MakeVec(
				ENCOUNT_SPTR_CHANP_CELL_SCALE,
				ENCOUNT_SPTR_CHANP_CELL_SCALE, 0 );
		for( i=0; i<ENCOUNT_SPTR_CHANP_CELL_NUM; i++ ){
			if( i < (ENCOUNT_SPTR_CHANP_CELL_NUM - 1) ){
				p_clact_res = &task_w->clact_res[i];
				seq = 0;
			}else{
				p_clact_res = &task_w->clact_res[i - 1];
				seq = 1;
			}

			task_w->clact[i] = ENC_CLACT_Add(
					&task_w->clact_sys, p_clact_res,
					0, 0, 0, 0);
			CLACT_SetDrawFlag( task_w->clact[i], FALSE );
			CLACT_AnmChg( task_w->clact[i], seq );
			CLACT_BGPriorityChg( task_w->clact[i], 1 );
		}

		// 主人公グラフィック登録
		if( task_w->hero_type ){
			// 男
//			ENC_CLACT_ResColorChange( task_w->clact[0], heapID, TRTYPE_BOY, ENCOUNT_SPTR_CHANP_COLOR_FADE_EVY, ENCOUNT_SPTR_CHANP_COLOR_FADE );
		}else{
			// 女
//			ENC_CLACT_ResColorChange( task_w->clact[0], heapID, TRTYPE_GIRL, ENCOUNT_SPTR_CHANP_COLOR_FADE_EVY, ENCOUNT_SPTR_CHANP_COLOR_FADE );
		}
//		CLACT_SetAffineParam( task_w->clact[0], CLACT_AFFINE_DOUBLE );
//		CLACT_SetScale( task_w->clact[0], &scale );
		EncountEffect_SPTR_ResColorChange( task_w->clact[0], heapID, task_w->hero_nclr,
				ENCOUNT_SPTR_CHANP_COLOR_FADE_EVY, ENCOUNT_SPTR_CHANP_COLOR_FADE);

		// 四天王グラフィック登録
//		ENC_CLACT_ResColorChange( task_w->clact[1], heapID, cp_def->enemy_tr_type, ENCOUNT_SPTR_CHANP_COLOR_FADE_EVY, ENCOUNT_SPTR_CHANP_COLOR_FADE );
//		CLACT_SetAffineParam( task_w->clact[1], CLACT_AFFINE_DOUBLE );
//		CLACT_SetScale( task_w->clact[1], &scale );
		EncountEffect_SPTR_ResColorChange( task_w->clact[1], heapID, cp_def->enemy_ncl,
					ENCOUNT_SPTR_CHANP_COLOR_FADE_EVY, ENCOUNT_SPTR_CHANP_COLOR_FADE);


		// BG面表示
		GF_Disp_GX_VisibleControl(GX_PLANEMASK_OBJ, VISIBLE_ON);

		// VSアニメ初期化
		EncountEffect_SpTr_VsAnmInit( &task_w->vsanm, &task_w->clact_sys, &task_w->clact_res[3], ENCOUNT_SPTR_CHANP_VSMARK_X, ENCOUNT_SPTR_CHANP_VSMARK_Y, heapID );


		// ３D面を２D面に書き込む
		ENC_GPrint_Init( eew->fsw );

		eew->seq ++;
		break;

	case ENCOUNT_SPTR_CHANP_FLASH_INI:

		EncountFlashTask(MASK_MAIN_DISPLAY, 16, 16,  &eew->wait, 1);
		eew->count = 0;
		eew->seq++;
		break;

	case ENCOUNT_SPTR_CHANP_FLASH_WAIT:
		eew->count ++;
		if( eew->count == 8 ){
			ENC_GPrint_SwitchOn();	// 3D表示と２D表示を切り替える
		}
		if( eew->wait ){
			eew->seq++;
		}
		break;

	case ENCOUNT_SPTR_CHANP_GPRINT_WAIT:
		if( ENC_GPrint_Check() == TRUE ){

#ifdef PLATINUM_MERGE_MSG
			// パーティクルを読み込んでおく
			ENC_GPrint_PTC_Load( eew->p_handle, NARC_field_encounteffect_chanpion_spa );
#endif
			// 3D面アルファ設定
			G2_SetBlendAlpha( GX_BLEND_PLANEMASK_BG0,
					GX_BLEND_PLANEMASK_BG1|GX_BLEND_PLANEMASK_BG2|GX_BLEND_PLANEMASK_BG3|GX_BLEND_PLANEMASK_OBJ,
					0, 8 );
			eew->seq++;
		}
		break;

	case ENCOUNT_SPTR_CHANP_HERO_IN:
		ENC_AddMoveReqFx( &task_w->oam_move_x,
				ENCOUNT_SPTR_CHANP_HERO_MOVE_SX,
				ENCOUNT_SPTR_CHANP_HERO_MOVE_EX,
				ENCOUNT_SPTR_CHANP_HERO_MOVE_SS,
				ENCOUNT_SPTR_CHANP_HERO_MOVE_SYNC );
		matrix = ENC_MakeVec(
				task_w->oam_move_x.x,
				ENCOUNT_SPTR_CHANP_HERO_Y, 0 );
		CLACT_SetMatrix( task_w->clact[0], &matrix );
		matrix.y += ENCOUNT_SPTR_CHANP_HERO_Y_WAKU_OFS;
		matrix.x += ENCOUNT_SPTR_CHANP_HERO_X_WAKU_OFS;
		CLACT_SetMatrix( task_w->clact[2], &matrix );
		CLACT_SetDrawFlag( task_w->clact[0], TRUE );
		CLACT_SetDrawFlag( task_w->clact[2], TRUE );


		// 敵
		ENC_AddMoveReqFx( &task_w->enemy_oam_move_x,
				ENCOUNT_SPTR_CHANP_ENEMY_MOVE_SX,
				ENCOUNT_SPTR_CHANP_ENEMY_MOVE_EX,
				ENCOUNT_SPTR_CHANP_ENEMY_MOVE_SS,
				ENCOUNT_SPTR_CHANP_ENEMY_MOVE_SYNC );
		matrix = ENC_MakeVec(
				task_w->enemy_oam_move_x.x,
				ENCOUNT_SPTR_CHANP_ENEMY_Y, 0 );
		CLACT_SetMatrix( task_w->clact[1], &matrix );
		matrix.y += ENCOUNT_SPTR_CHANP_ENEMY_Y_WAKU_OFS;
		matrix.x += ENCOUNT_SPTR_CHANP_ENEMY_X_WAKU_OFS;
		CLACT_SetMatrix( task_w->clact[3], &matrix );
		CLACT_SetDrawFlag( task_w->clact[1], TRUE );
		CLACT_SetDrawFlag( task_w->clact[3], TRUE );


		// トレーナー名表示用ビットマップ作成
		{
			STRBUF* p_str;

#ifdef PLATINUM_MERGE_MSG
			// パレット読み込み
			ArcUtil_HDL_PalSet( eew->p_handle,
					NARC_field_encounteffect_cutin_gym_font_NCLR,
					PALTYPE_MAIN_BG, ENCOUNT_SPTR_CHANP_TRNAME_PAL*0x20, 0x20, heapID );
#endif
			GF_Disp_GX_VisibleControl(GX_PLANEMASK_BG2, VISIBLE_OFF);
			GF_BGL_BmpWinAdd( eew->fsw->bgl, &task_w->trnamewin,
					GF_BGL_FRAME2_M, ENCOUNT_SPTR_CHANP_TRNAME_X, ENCOUNT_SPTR_CHANP_TRNAME_Y,
					ENCOUNT_SPTR_CHANP_TRNAME_SIZX, ENCOUNT_SPTR_CHANP_TRNAME_SIZY,
					ENCOUNT_SPTR_CHANP_TRNAME_PAL, ENCOUNT_SPTR_CHANP_TRNAME_CGX );
			GF_BGL_BmpWinDataFill( &task_w->trnamewin, 0 );
			p_str = EncountEffect_SpTr_Gym_TrTypeNameGet( cp_def->tr_no, heapID );
			GF_STR_PrintColor( &task_w->trnamewin, FONT_SYSTEM,
										   p_str, 0, 0, MSG_ALLPUT,
										   ENCOUNT_SPTR_CHANP_TRNAME_COL, NULL);
			STRBUF_Delete( p_str );	// 破棄わすれ注意！
		}

		eew->wait = ENCOUNT_SPTR_CHANP_HERO_EFFECT_WAIT;
		eew->seq ++;
		break;

	case ENCOUNT_SPTR_CHANP_HERO_INWAIT:

		// パーティクル開始タイミングを計算
		if( eew->wait > 0 ){
			eew->wait --;
			if( eew->wait == 0 ){
				// パーティクル開始
				ENC_GPrint_PTC_Start( 3 );
				GF_Disp_GX_VisibleControl(
					GX_PLANEMASK_BG0, VISIBLE_ON );

				// trainer名ON
				GF_Disp_GX_VisibleControl(GX_PLANEMASK_BG2, VISIBLE_ON);
			}
		}else{

			// その他ならVSアニメを流す
			EncountEffect_SpTr_VsAnmMain( &task_w->vsanm );
		}

		result = ENC_AddMoveMainFx( &task_w->oam_move_x );
		matrix = ENC_MakeVec(
				task_w->oam_move_x.x,
				ENCOUNT_SPTR_CHANP_HERO_Y, 0 );
		task_w->pos_hero = matrix;	// 基準座標
		CLACT_SetMatrix( task_w->clact[0], &matrix );
		matrix.y += ENCOUNT_SPTR_CHANP_HERO_Y_WAKU_OFS;
		matrix.x += ENCOUNT_SPTR_CHANP_HERO_X_WAKU_OFS;
		CLACT_SetMatrix( task_w->clact[2], &matrix );

		// 敵
		result = ENC_AddMoveMainFx( &task_w->enemy_oam_move_x );
		matrix = ENC_MakeVec(
				task_w->enemy_oam_move_x.x,
				ENCOUNT_SPTR_CHANP_ENEMY_Y, 0 );
		task_w->pos_enemy = matrix;	// 基準座標
		CLACT_SetMatrix( task_w->clact[1], &matrix );
		matrix.y += ENCOUNT_SPTR_CHANP_ENEMY_Y_WAKU_OFS;
		matrix.x += ENCOUNT_SPTR_CHANP_ENEMY_X_WAKU_OFS;
		CLACT_SetMatrix( task_w->clact[3], &matrix );

		if( result == TRUE ){
			eew->seq ++;
		}
		break;


	case ENCOUNT_SPTR_CHANP_HERO_FLASHOUT:
		result = EncountEffect_SpTr_VsAnmMain( &task_w->vsanm );
		result2 = ENC_GPrint_PTC_EndCheck();
		if( (result == FALSE) || (result2 == FALSE) ){
			break;
		}
		ENC_MoveReq( &task_w->flash,
				0, 16,
				ENCOUNT_SPTR_CHANP_HERO_FLASHOUT_SYNC);

		// このパーティクルを破棄
		ENC_GPrint_PTC_Delete();

		eew->seq ++;
		break;


	case ENCOUNT_SPTR_CHANP_HERO_FLASHOUTWAIT:
		result = ENC_MoveMain( &task_w->flash );
		ENC_SetMasterBrightnessVblank( &task_w->flash.x );
		if( result == TRUE ){
			// 主人公のカラーパレット変更
			// OAMのカラーパレット変更
//			ENC_CLACT_ResColorChange( task_w->clact[0], heapID, task_w->hero_type, 0, ENCOUNT_SPTR_CHANP_COLOR_FADE );
			EncountEffect_SPTR_ResColorChange( task_w->clact[0], heapID, task_w->hero_nclr, 0, ENCOUNT_SPTR_CHANP_COLOR_FADE );

			// 敵
//			ENC_CLACT_ResColorChange( task_w->clact[1], heapID, cp_def->enemy_tr_type, 0,ENCOUNT_SPTR_CHANP_COLOR_FADE );
			EncountEffect_SPTR_ResColorChange( task_w->clact[1], heapID, cp_def->enemy_ncl, 0, ENCOUNT_SPTR_CHANP_COLOR_FADE );

			// 土台のアニメ開始
			CLACT_SetAnmFlag( task_w->clact[2], TRUE );
			CLACT_SetAnmFrame( task_w->clact[2], FX32_ONE*2 );
			CLACT_SetAnmFlag( task_w->clact[3], TRUE );
			CLACT_SetAnmFrame( task_w->clact[3], FX32_ONE*2 );


			//  次のパーティクルを読み込む
			//  動きが止まるのがわかってもよいように真っ白のときに行う
#ifdef PLATINUM_MERGE_MSG
			ENC_GPrint_PTC_Load( eew->p_handle, NARC_field_encounteffect_chanpion2_spa );
#endif

			eew->seq++;
		}
		break;

	case ENCOUNT_SPTR_CHANP_HERO_FLASHIN:
		ENC_MoveReq( &task_w->flash,
				16,0,
				ENCOUNT_SPTR_CHANP_HERO_FLASHIN_SYNC);

		// 背面パーティクル開始
		ENC_GPrint_PTC_Start( 4 );
		GF_BGL_PrioritySet( GF_BGL_FRAME0_M, 1 );

		eew->seq++;
		break;

	case ENCOUNT_SPTR_CHANP_HERO_FLASHINWAIT:
		result = ENC_MoveMain( &task_w->flash );
		ENC_SetMasterBrightnessVblank( &task_w->flash.x );
		if( result == TRUE ){
			eew->seq++;

			// 主人公がこすれるまでのウエイト
			eew->wait = ENCOUNT_SPTR_CHANP_BT_IN_WAIT;

		}
		break;

	// こすれるアニメ
	case ENCOUNT_SPTR_CHANP_BT_IN:

		// ウエイト
		if( eew->wait > 0 ){
			eew->wait --;
			break;
		}


		// 動作する値
		ENC_AddMoveReqFx( &task_w->oam_move_x,
				ENCOUNT_SPTR_CHANP_BT_IN_MOVE_SX,
				ENCOUNT_SPTR_CHANP_BT_IN_MOVE_EX,
				ENCOUNT_SPTR_CHANP_BT_IN_MOVE_SSX,
				cp_def->bt_in_move_sync );
		ENC_AddMoveReqFx( &task_w->oam_move_y,
				ENCOUNT_SPTR_CHANP_BT_IN_MOVE_SY,
				ENCOUNT_SPTR_CHANP_BT_IN_MOVE_EY,
				ENCOUNT_SPTR_CHANP_BT_IN_MOVE_SSY,
				cp_def->bt_in_move_sync );

		eew->wait = 0;

		eew->seq++;
		break;

	case ENCOUNT_SPTR_CHANP_BT_INWAIT:

		eew->wait ++;

		result = ENC_AddMoveMainFx( &task_w->oam_move_x );
		ENC_AddMoveMainFx( &task_w->oam_move_y );

		// 主人公
		if( ((eew->wait / ENCOUNT_SPTR_CHANP_BT_IN_MOVE_CHG)%2) == 0 ){
			matrix = ENC_MakeVec(
					task_w->pos_hero.x + task_w->oam_move_x.x,
					task_w->pos_hero.y + task_w->oam_move_y.x, 0 );
		}else{
			matrix = ENC_MakeVec(
					task_w->pos_hero.x - task_w->oam_move_x.x,
					task_w->pos_hero.y - task_w->oam_move_y.x, 0 );
		}
		if( result ){
			task_w->pos_hero = matrix;	// 基準座標
		}
		CLACT_SetMatrix( task_w->clact[0], &matrix );
		matrix.y += ENCOUNT_SPTR_CHANP_HERO_Y_WAKU_OFS;
		matrix.x += ENCOUNT_SPTR_CHANP_HERO_X_WAKU_OFS;
		CLACT_SetMatrix( task_w->clact[2], &matrix );

		// 敵
		if( ((eew->wait / ENCOUNT_SPTR_CHANP_BT_IN_MOVE_CHG)%2) == 0 ){
			matrix = ENC_MakeVec(
					task_w->pos_enemy.x - task_w->oam_move_x.x,
					task_w->pos_enemy.y - task_w->oam_move_y.x, 0 );
		}else{
			matrix = ENC_MakeVec(
					task_w->pos_enemy.x + task_w->oam_move_x.x,
					task_w->pos_enemy.y + task_w->oam_move_y.x, 0 );
		}
		if( result ){
			task_w->pos_enemy = matrix;	// 基準座標
		}
		CLACT_SetMatrix( task_w->clact[1], &matrix );
		matrix.y += ENCOUNT_SPTR_CHANP_ENEMY_Y_WAKU_OFS;
		matrix.x += ENCOUNT_SPTR_CHANP_ENEMY_X_WAKU_OFS;
		CLACT_SetMatrix( task_w->clact[3], &matrix );

		if( result ){
			eew->seq ++;

			// トレーナー名OFF
			GF_Disp_GX_VisibleControl(GX_PLANEMASK_BG2, VISIBLE_OFF);

			// OAM
			ENC_AddMoveReqFx( &task_w->oam_move_x,
					0, ENCOUNT_SPTR_CHANP_OMA_MOVE_X,
					ENCOUNT_SPTR_CHANP_OAM_MOVE_XSS,
					ENCOUNT_SPTR_CHANP_WIPE_OUT_SYNC );
			ENC_AddMoveReqFx( &task_w->oam_move_y,
					0, ENCOUNT_SPTR_CHANP_OMA_MOVE_Y,
					ENCOUNT_SPTR_CHANP_OAM_MOVE_YSS,
					ENCOUNT_SPTR_CHANP_WIPE_OUT_SYNC );

			// ホワイトアウト
			WIPE_SYS_Start( WIPE_PATTERN_M, WIPE_TYPE_FADEOUT, WIPE_TYPE_FADEOUT, WIPE_FADE_WHITE, ENCOUNT_SPTR_CHANP_WIPE_OUT_SYNC_WIPE, 1, HEAPID_FIELD );
		}
		break;

	case ENCOUNT_SPTR_CHANP_WIPEWAIT:
		ENC_AddMoveMainFx( &task_w->oam_move_x );
		ENC_AddMoveMainFx( &task_w->oam_move_y );

		// 主人公側
		matrix = ENC_MakeVec(
				task_w->pos_hero.x - task_w->oam_move_x.x,
				task_w->pos_hero.y - task_w->oam_move_y.x, 0 );
		CLACT_SetMatrix( task_w->clact[0], &matrix );
		matrix.y += ENCOUNT_SPTR_CHANP_HERO_Y_WAKU_OFS;
		matrix.x += ENCOUNT_SPTR_CHANP_HERO_X_WAKU_OFS;
		CLACT_SetMatrix( task_w->clact[2], &matrix );

		// 敵公側
		matrix = ENC_MakeVec(
				task_w->pos_enemy.x + task_w->oam_move_x.x,
				task_w->pos_enemy.y + task_w->oam_move_y.x, 0 );
		CLACT_SetMatrix( task_w->clact[1], &matrix );
		matrix.y += ENCOUNT_SPTR_CHANP_ENEMY_Y_WAKU_OFS;
		matrix.x += ENCOUNT_SPTR_CHANP_ENEMY_X_WAKU_OFS;
		CLACT_SetMatrix( task_w->clact[3], &matrix );


		if( WIPE_SYS_EndCheck() ) {
			eew->seq ++;
		}
		break;

	case ENCOUNT_SPTR_CHANP_END:
		WIPE_SetBrightness( WIPE_DISP_SUB, WIPE_FADE_WHITE );

		if(eew->end != NULL){
			*(eew->end) = TRUE;		// タスク終了を報告
		}

		// 破棄
		EncountEffect_SpTr_VsAnmExit( &task_w->vsanm );

		// trainer名BMP
		GF_BGL_BmpWinDel( &task_w->trnamewin );

		// OAM破棄
		for( i=0; i<ENCOUNT_SPTR_CHANP_CELL_NUM; i++ ){
			CLACT_Delete( task_w->clact[i] );
		}
		for( i=0; i<ENCOUNT_SPTR_CHANP_CELL_RES_NUM; i++ ){
			ENC_CLACT_ResDeleteEasy( &task_w->clact_sys, &task_w->clact_res[i] );
		}
		ENC_CLACT_Delete( &task_w->clact_sys );

		ENC_GPrint_PTC_Delete();

		ENC_GPrint_Exit();

		G2_BlendNone();

		return TRUE;
	}

	if( eew->seq != ENCOUNT_SPTR_CHANP_END ){
		CLACT_Draw( task_w->clact_sys.cas );

		if( ENCOUNT_SPTR_CHANP_GPRINT_WAIT < eew->seq ){
			GF_G3X_Reset();
			ENC_GPrint_PTC_Move();
			ENC_GPrint_Draw();
			GF_G3_RequestSwapBuffers(GX_SORTMODE_AUTO, GX_BUFFERMODE_Z);
		}
	}

	return FALSE;
}

//-----------------------------------------------------------------------------
/**
 *	@brief	カラーパレット変更
 *
 *	@param	CLACT_WORK_PTR clact
 *	@param	heap
 *	@param	nclr
 *	@param	evy
 *	@param	next_rgb
 *
 *	@retval
 */
//-----------------------------------------------------------------------------
static void EncountEffect_SPTR_ResColorChange( CLACT_WORK_PTR clact, HEAPID heap, int nclr, u8 evy, u16 next_rgb )
{
	NNSG2dPaletteData* p_pltt;
	NNSG2dImagePaletteProxy * pltt;
	void* p_pltt_buff;
	u16* dest;
	int size;

	// データ作成先
	dest = sys_AllocMemory( heap, 32 );

	// キャラクタとパレット取得
	p_pltt_buff = ArcUtil_PalDataGet( ARC_ENCOUNTEFFECT, nclr, &p_pltt, heap );

	SoftFade( p_pltt->pRawData, dest, 16, evy, next_rgb );

	// パレット転送
	size = 32;
	pltt = CLACT_PaletteProxyGet( clact );
	DC_FlushRange( dest, size );
	GX_LoadOBJPltt(
			dest,
			NNS_G2dGetImagePaletteLocation( pltt, NNS_G2D_VRAM_TYPE_2DMAIN ),
			size );

	sys_FreeMemoryEz( dest );
	sys_FreeMemoryEz( p_pltt_buff );
}

//----------------------------------------------------------------------------
/**
 *	@brief	四天王　チャンピオン
 */
//-----------------------------------------------------------------------------
void EncountEffect_SPTR_Siten00(TCB_PTR tcb, void* work)
{
#if 0
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	static ENC_GPRINT_WK debug_wk;

	switch( eew->seq ){
	case 0:
		ENC_GPrint_Init( &debug_wk, eew->fsw );
		eew->seq ++;
		break;

	case 1:
		result = ENC_GPrint_Check( &debug_wk );
		if( result ){
			eew->seq ++;
		}
		break;

	case 2:
		{
			//  勝手に３D描画処理
			GF_G3X_Reset();

			GFC_CameraLookAtZ();

			/* ジオメトリ＆レンダリングエンジン関連メモリのスワップ */
			GF_G3_RequestSwapBuffers(GX_SORTMODE_AUTO, SwapBuffMode);

			ENC_End( eew, tcb );
		}
		break;
	}

#endif

#if 1
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_ChanpMain( eew, HEAPID_FIELD, &EncountSpTr_ChanpParam[0] );
	if( result == TRUE ){
		ENC_End( eew, tcb );
	}
#endif
}
void EncountEffect_SPTR_Siten01(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_ChanpMain( eew, HEAPID_FIELD, &EncountSpTr_ChanpParam[1] );
	if( result == TRUE ){
		ENC_End( eew, tcb );
	}
}
void EncountEffect_SPTR_Siten02(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_ChanpMain( eew, HEAPID_FIELD, &EncountSpTr_ChanpParam[2] );
	if( result == TRUE ){
		ENC_End( eew, tcb );
	}
}
void EncountEffect_SPTR_Siten03(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_ChanpMain( eew, HEAPID_FIELD, &EncountSpTr_ChanpParam[3] );
	if( result == TRUE ){
		ENC_End( eew, tcb );
	}
}
void EncountEffect_SPTR_Chanpion(TCB_PTR tcb, void* work)
{
	ENCOUNT_EFFECT_WORK *eew = work;
	BOOL result;
	result = EncountEffect_SpTr_ChanpMain( eew, HEAPID_FIELD, &EncountSpTr_ChanpParam[4] );
	if( result == TRUE ){
		ENC_End( eew, tcb );
	}
}
